package cn.itcast.mq.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.FanoutExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/*
 *RabbitMQ声明组件的配置类
 *@Author gegaojie
 *@Date 2025/1/5 14:52
 */
@Configuration
public class RabbitConfig {
    /**
     * 简单工作模型-声明队列
     *
     * @return
     */
    @Bean
    public Queue simpleQueue() {
        return new Queue("simple.queue");
    }

    /**
     * 工作队列模型-声明队列
     *
     * @return
     */
    @Bean
    public Queue workQueue() {
        return new Queue("work.queue");
    }

    /**
     * 广播模型-声明交换机
     *
     * @return
     */
    @Bean
    public FanoutExchange fanoutExchange() {
        return new FanoutExchange("fanout.exchange");
    }

    /**
     * 广播模型-声明队列1
     *
     * @return
     */
    @Bean
    public Queue fanoutQueue1() {
        return new Queue("fanout.queue1");
    }

    /**
     * 广播模型-声明队列2
     *
     * @return
     */
    @Bean
    public Queue fanoutQueue2() {
        return new Queue("fanout.queue2");
    }

    /**
     * 广播模型-生命绑定关系-绑定交换机和队列1
     *
     * @return
     */
    @Bean
    public Binding bindFanoutQueue1() {
        return BindingBuilder.bind(fanoutQueue1()).to(fanoutExchange());
    }
   /* @Bean
    public Binding bindFanoutQueue1(Queue fanoutQueue1, FanoutExchange fanoutExchange) {
        return BindingBuilder.bind(fanoutQueue1).to(fanoutExchange);
    }*/

    /**
     * 广播模型-生命绑定关系-绑定交换机和队列2
     *
     * @return
     */
    @Bean
    public Binding bindFanoutQueue2() {
        return BindingBuilder.bind(fanoutQueue2()).to(fanoutExchange());
    }

    /**
     * 声明对象类型消息的存储队列
     * @return
     */
    @Bean
    public Queue objectQueue1(){
    return new Queue("object.queue");
    }
}
